package com.zhb86.kuaipai.ui.home;

import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;

import com.superyee.commonlib.ui.BaseActivity;
import com.zhb86.kuaipai.R;

/**
 * 查看其它用户主页
 */
public class ATUserHomePage extends BaseActivity {

    private GestureDetector mGestureDetector;
    private int distanceX;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_user_home_page;
    }

    @Override
    protected void initPerData(Bundle savedInstanceState) {

    }

    @Override
    protected void initView() {
        distanceX = getResources().getDimensionPixelOffset(com.superyee.commonlib.R.dimen.dp_100);
        mGestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {
            @Override
            public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                // 判断纵向滑动是否过大，过大的话不允许切换界面
                if (Math.abs(e2.getRawY() - e1.getRawY()) > distanceX) {
                    return true;
                }
                // 判断滑动是否龟速，如果速度过慢也不允许滑动到另一页
                if (Math.abs(velocityX) < distanceX / 2) {
                    return true;
                }
                // 向右滑动,上一页
                if (e2.getRawX() - e1.getRawX() > distanceX) {
                    finish();
                    return true;
                }
                // 向左滑动,下一页
                if (e1.getRawX() - e2.getRawX() > distanceX) {
                    return true;
                }
                return false;
            }
        });
    }

    @Override
    protected void initData() {

    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        return mGestureDetector.onTouchEvent(event);
    }

    @Override
    protected void addListener() {

    }

    @Override
    protected void removeListener() {

    }

    @Override
    public void onReceiverNotify(int action, Object obj, int statusCode) {

    }
}
